home *** CD-ROM | disk | FTP | other *** search
- Path: surfnet.nl!sun4nl!ittpub!ittpub!nntp
- Newsgroups: comp.lang.c++
- Subject: Re: Question: outLined inlines/ Vtab replication
- Message-ID: <1996Mar8.172247.1796@ittpub>
- From: wil@ittpub.nl (Wil Evers)
- Date: 8 Mar 96 17:22:47 WET
- References: <4hp08l$5sd@newdelph.cig.mot.com>
- Distribution: world
- Nntp-Posting-Host: lintilla
-
- In article <4hp08l$5sd@newdelph.cig.mot.com> Martin O'Hara <oharam>
- writes:
-
- > I have a couple of questions that Im not 100 percent on
- >
- > If a function is declared inline by the programmer but the address of
- > this function is taken in the code somewhere then the compiler will
- > generate a callable function. This may also happpen if the inline is
- > recursive or too big.
- >
- > Q. Is a copy of such a function placed in each translation unit in
- > which it is needed ( code duplication). Is this an "outlined inline"?
-
- Normally, yes. Inline functions have internal linkage, even when they're
- not inlined. However, I don't think a compiler would violate the standard
- by not replicating the code if it were able to somehow uniquely identify a
- translation unit where it can put the `outlined' inline function. See
- below.
-
- > Q. Can there exist inline expanded code representing the function and
- > also a callable version of the function in different parts of a
- > program.? Or will the compiler decide that if all occorrences of the
- > function cannot be inline expanded then the function will just be a
- > normal one?
-
- Yes. I would expect this to happen if the address of a simple inline
- function is taken: a decent compiler will still try to inline where it
- can.
-
- > I also have a question regarding VTABs
- >
- > The C++ standard states that smart compilers will look for the first non
- > inline virtual function definition of a class and place one copy of the
- > VTAB in that translation unit.
-
- Where in the C++ standard is this specified? I don't think the standard
- requires the use of vtbls at all. vtbls are just a (commonly used) way to
- implement virtual member functions. In practice, the technique you
- describe is a common heuristic compilers use to determine where to put the
- vtbl.
-
- > In what cases will the VTAB be replicated (anywhere the class
- > h file is included) by a smart compiler.
- > A. If there are no non inline virtuals?
- > B If there are no non virtual functions in the class (C++ standard)?
-
- Given the above heuristic, a decent compiler will have to replicate the
- vtbl if (1) it cannot uniquely identify a translation unit where it should
- put it - this happens when a class has no non-inline virtuals - and (2)
- the compiler needs an address for the vtbl - I would expect this to happen
- if the translation unit contains a (possibly inlined) constructor or
- destructor definition that may (indirectly) call one of the class's
- virtual functions.
-
- Regards,
-
- - Wil
-
-